<!DOCTYPE html>
<#assign f = JspTaglibs["http://www.casic304.cn/f"] />
<#assign dicSelect = JspTaglibs["http://www.casic304.cn/dicSelect"]/>
<#assign SourceDept = JspTaglibs["http://www.casic304.cn/SourceDept"]/>
<html>
<head>
  <meta charset="utf-8">
  <title>化学物理电源信息列表</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="${ctx}/layui/css/layui.css" media="all"/>
  <link rel="stylesheet" href="${ctx}/qbdmsStatic/iconfont/iconfont.css"/>
  <link rel="stylesheet" href="${ctx}/qbdmsStatic/style/qbdms.css">
  <script type="text/javascript">
    var __ctx = "${ctx}";
  </script>
</head>
<body class="listBody">
<div class="qbdms-list">
  <div class="layui-table-view-body">
    <table id="wQbdChemicalPhysicsInfoTable" lay-filter="wQbdChemicalPhysicsInfoTable"></table>
  </div>
</div>
<!-- 列表头部工具栏 -->
<script type="text/html" id="wQbdChemicalPhysicsInfoHeaderToolsBar">
  <div class="ccpui-enterSel">
      <div class="layui-btn-container">
        <@f.a alias="xzanhxwldy2,xzanhxwldy3" css="layui-btn layui-btn-sm fillBtn" event="add">
        <span>新增</span>
      </@f.a>
      <@f.a alias="scanhxwldy2,scanhxwldy3" css="layui-btn layui-btn-sm" event="delete">
      <span>删除</span>
    </@f.a>
    <a class="layui-btn layui-btn-sm" lay-event="export">
    <span>导出</span>
    </a>
  <@f.a alias="dranhxwldy2,dranhxwldy3" event="import" css="layui-btn layui-btn-sm" >
  <span>导入</span>
  </@f.a>

    <@f.a alias="sbanhxwldy2,sbanhxwldy3" event="report" css="layui-btn layui-btn-sm" >
    <span>上报</span>
  </@f.a>
  <a class="layui-btn layui-btn-sm" lay-event="listStyle">
    <span>配置列</span>
  </a>


  </div>
  <form class="layui-form" action="" lay-filter="wQbdChemicalPhysicsInfoQueryForm">
    <div class="layui-form-body selch">
      <div class="table-top-filter layui-row">
        <@SourceDept.dept css="layui-input filter-value "/>
        <div class="qbdms-listForm">
          <label class="layui-form-label">种类</label>
          <div class="layui-input-block">
            <select name="Q_type_S" lay-verify="required" class="layui-input filter-value"
                    lay-filter="type">
            </select>
          </div>
        </div>
        <div class="qbdms-listForm">
          <label class="layui-form-label">所属产品类别</label>
          <div class="layui-input-block">
            <select type="text" class="layui-input filter-value" name="Q_productCategory_S"
                    id="productCategory" id="Q_productCategory_L" lay-filter="productCategory"/>
          </div>
        </div>
        <div class="qbdms-listForm">
          <label class="layui-form-label">产品名称</label>
          <div class="layui-input-block">
            <select type="text" class="layui-input filter-value" name="Q_productName_S"
                    id="productName" lay-filter="productName"/>
          </div>
        </div>
        <div class="qbdms-listForm">
          <label class="layui-form-label">问题原因</label>
          <div class="layui-input-block">
            <@dicSelect.dic name="Q_problemCauses_S" css="layui-input filter-value" nodeKey="wtyy"/>
          </div>
        </div>
        <div class="qbdms-listForm">
          <label class="layui-form-label">阶段</label>
          <div class="layui-input-block">
            <select id="stage" name="Q_stage_S"  type="text"
                    class="layui-input filter-value"  lay-filter="stage" id="stage"/>
          </div>
        </div>
        <div class="qbdms-listForm">
          <label class="layui-form-label">批次号</label>
          <div class="layui-input-block">
            <input type="text" class="layui-input filter-value" name="Q_batchNumber_SL"
                   placeholder="请输入"/>
          </div>
        </div>
        <div class="qbdms-listForm">
          <label class="layui-form-label">检测开始日期</label>
          <div class="layui-input-block">
            <input type="text" class="layui-input start_time1 filter-value"
                   name="Q_beginMonitoringTime_DL" placeholder="请输入"/>
          </div>
        </div>
        <div class="qbdms-listForm">
          <label class="layui-form-label">检测结束日期</label>
          <div class="layui-input-block">
            <input type="text" class="layui-input end_time1 filter-value"
                   name="Q_endMonitoringTime_DG" placeholder="请输入" />
        </div>

          </div>
        <div class="qbdms-listForm">
          <label class="layui-form-label">外协单位</label>
          <div class="layui-input-block">
            <input type="text" class="layui-input filter-value" name="Q_outsourcingUnit_SL"
                   placeholder="请输入"/>
          </div>
        </div>
        </div>
       <div class="selchBtn">
        <a class="layui-btn layui-btn-sm fillBtn" lay-event="query">
          <span>查询</span>
        </a>
        <div class="layui-btn-group">
          <button type="button" class="layui-btn layui-btn-sm" lay-event="clears"
                  style="width: 28px;font-size: 12px;padding: 0">
            <i class="iconfont  data-iconcommon_refresh"></i>
          </button>
          <button type="button" class="layui-btn layui-btn-sm screenParent" lay-event="screen"
                  style="width: 28px;font-size: 12px;padding: 0">
            <i class="iconfont data-iconcommon_downarrow screen"></i>
          </button>
        </div>
      </div>
      </div>
    </form>
  </div>

</script>
<!-- 右侧工具栏 -->
<script type="text/html" id="wQbdChemicalPhysicsInfoRightToolsBar">
  {{# if('${userId}'==d.createBy && d.allowEdit){}}
  <@f.a alias="bjanhxwldy2,bjanhxwldy3" event="edit" css="RightBtn">编辑</@f.a>
  {{#  } }}
  <a class="RightBtn" lay-event="particulars">详情</a>
  {{# if('${userId}'==d.createBy  && d.allowDel){ }}
  <@f.a alias="scanhxwldy2,scanhxwldy3" event="del" css="RightBtn">删除</@f.a>
  {{#  } }}
</script>
<script src="${ctx}/qbdmsStatic/public/configFile.js"></script>
<script src="${ctx}/layui/layui.js"></script>
<script>
  //一般直接写在一个js文件中
  layui.config({
    base: serverPath.qbdmsPath + staticPath.qbdmsPath //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(
      ['index', 'table', 'setter',  'common', 'publicMethods', 'jquery', 'layer','form','propsHandle'],
      function () {
        var table = layui.table;
        var common = layui.common;
        var publicMethods = layui.publicMethods;
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
          var propsHandle = layui.propsHandle;
          var defProps = {
                  //viewMould: 'form/formDef/view/formDesign/moulds/', // 组件模块 存放文件 *****
                  viewMould: 'moulds/', // 组件模块 存放文件 *****
                  selectorBtn: '.selectorBtn'
              },
              temQuery = new propsHandle();  // 实例化模板功能部分
          temQuery.initTem({
              selectorBtn: defProps.selectorBtn,
              selectorTemPath: setter.views + defProps.viewMould
          });
        common.tableSort('wQbdChemicalPhysicsInfoTable');
        var typeValue;
        var productCategoryValue;
        var productCategoryData=[];
        var productNameValue;
        var productNameData=[];
        var stageValue;
        var stageData=[];
        var tableH=publicMethods.tabHeight();
        form.on('select(type)', function (data) {
          typeValue = data.value;
          getDicData(1);
          form.render();
        });
        form.on('select(productCategory)', function (data) {
          productCategoryValue = data.value;
          getDicData(2);
          form.render();
        });
        form.on('select(productName)', function (data) {
          productNameValue = data.value;
          form.render();
        });
        form.on('select(stage)', function (data) {
          stageValue = data.value;
          form.render();
        });
        form.render();
        var cols = '${cols}';
        //第一个实例
        window.tableInstace = function(tcols){
          if(tcols){
            cols = tcols;
          }
          if(cols){
            cols = JSON.parse(cols,function(k,v){
              if(v.indexOf && v.indexOf('function') > -1){
                return eval("(function(){return "+v+" })()")
              }
              return v;
            })
          }

          var showSta={field: 'reportStatusStr', title: '状态',sort:false, sortname: 'report_status',templet: function(d){
              return common.stateType(d);
            }};
          var source={field: 'filldept', title: '数据来源单位',sort:false, sortname: 'filldept',minWidth:'140'};
          if('${currentSystemLevel}'=='GROUPLEVEL'){
            showSta={field: 'reportStatusStr', title: '状态',sort:false, sortname: 'report_status',hide:true,minWidth:'150'};
            source={field: 'filldeptHospital', title: '数据来源单位',sort:false, sortname: 'filldepthospital',minWidth:'140'};
          }

          window.tableInstace.initCols = [ //初始化的表头， 这里替换成自己的初始化表头json
            {type: 'checkbox', fixed: 'left'}
            ,{field: 'sn', type: 'numbers', title: '序号',minWidth:'90', fixed: 'left'}
            ,source
            ,{
              field: 'monitoringTime',
              title: '检测日期',
              sort: false,
              sortname: 'monitoring_time',
              templet: function (d) {
                return publicMethods.timeData(d.monitoringTime);
              },minWidth:'120'
            }
            , {field: 'type', title: '种类', sort: false, sortname: 'type',minWidth:'150'}
            , {field: 'productCategory', title: '所属产品类别', sort: false, sortname: 'product_category',minWidth:'150'}
            , {field: 'productName', title: '产品名称', sort: false, sortname: 'product_name',minWidth:'150'}
            , {field: 'productCode', title: '产品代号', sort: false,minWidth:'150', hide:true}
            , {field: 'batchNumber', title: '批次号', sort: false, sortname: 'batch_number',minWidth:'100'}
            , {field: 'atTheStage', title: '所处阶段', sort: false,minWidth:'100', hide:true}
            , {
              field: 'defectiveProductsNumber',
              title: '出问题产品数量',
              sort: false,
              align: 'right',
              sortname: 'defective_products_number'
              ,minWidth:'150'
            }
            , {field: 'stage', title: '阶段', sort: false, sortname: 'stage',minWidth:'100'}
            , {field: 'deliveryQuantity', title: '交付数量', hide:true, sort: false,minWidth:'100'}
            , {field: 'isQualified', title: '本批是否合格',  hide:true,sort: false,minWidth:'100'}
            , {field: 'problemCauses', title: '问题原因',  hide:true,sort: false,minWidth:'100'}
            , {field: 'defectiveProductsNumber', title: '出问题产品数量（只/组/台/套）',  hide:true,sort: false,minWidth:'100'}
            , {field: 'notMeetSpecifications', title: '不满足技术指标',  hide:true,sort: false,minWidth:'100'}
            , {field: 'outsourcingUnit', title: '外协单位', sort: false, sortname: 'outsourcing_unit',minWidth:'150'}
            ,showSta
            ,{
              fixed: 'right',
              width:200,
              title: '管理',
              toolbar: '#wQbdChemicalPhysicsInfoRightToolsBar',minWidth:'150'
            }
          ];

          window.tableInstace.tRender =  table.render({
            elem: '#wQbdChemicalPhysicsInfoTable'
            ,height:tableH
            ,url: '${ctx}/qbdms/wQbdChemicalPhysicsInfo/list'
            ,page: publicMethods.pageFun() //开启分页
            ,defaultToolbar: ['']
            ,limit: 20
            ,toolbar: '#wQbdChemicalPhysicsInfoHeaderToolsBar'
            ,method: 'post'
            ,autoSort: false //是否排序
            ,cols: [cols?cols:window.tableInstace.initCols]
            ,done:function () {
              common.tableSelectCon('.ccpui-enterSel .layui-form input','a[lay-event=query]','.ccpui-enterSel');
            }
            ,parseData: function(res){ //res 即为原始返回的数据
              common.parseDataList(res,['batchNumber','defectiveProductsNumber','stage','outsourcingUnit']);
              return {
                "code": res.code, //解析接口状态
                "msg": res.msg, //解析提示文本
                "count": res.count, //解析数据长度
                "data": res.data //解析数据列表
              };
            }
          });
        };
        window.tableInstace(cols);


        function dateReflash() {
          publicMethods.reflashDate({startName: '.start_time1', endName: '.end_time1'});
          var typeList = eval('${typeList}'); //种类
          common.initDicData("Q_type_S", typeList);
          common.initDicData("Q_productCategory_S", productCategoryData);
          common.initDicData("Q_productName_S", productNameData);
          common.initDicData("Q_stage_S", stageData);
          // getDicData(1);
          // getDicData(2);
          if (null != productCategoryValue && "" != productCategoryValue) {
            $('#productCategory').val(productCategoryValue);
          }
          if (null != productNameValue && "" != productNameValue) {
            $('#productName').val(productNameValue);
          }
          if (null != stageValue && "" != stageValue) {
            $('#stage').val(stageValue);
          }
        }

        function clear() {
          publicMethods.reflashDate({startName: '.start_time1', endName: '.end_time1'});
          var typeList = eval('${typeList}'); //种类
          common.initDicData("Q_type_S", typeList)
          productCategoryValue = "";
          productNameValue = "";
          stageValue = "";
          form.render();
        }

        function reflashQuery(isClear) {
          common.tableConditionRender("wQbdChemicalPhysicsInfoTable",
              "wQbdChemicalPhysicsInfoQueryForm", {where: {}}, isClear);
        }

        function getDicData(value) {
          var data;
          if (value === 1) {
            data = {
              "typeValue": typeValue
            }
          } else {
            data = {
              "typeValue": typeValue,
              "productCategoryValue": productCategoryValue
            }
          }

          if (null != typeValue && typeValue != "") {
            $.ajax({
              url: "${ctx}/qbdms/wQbdChemicalPhysicsInfo/getSelectData",
              type: "post",
              data: data,
              dataType: 'json',
              async: false,
              success: function (data) {
                if (1 === value) {
                  $("#productCategory").empty();
                  $("#productName").empty();
                  common.initDicData("Q_productCategory_S", data)
                  productCategoryData=data;
                  if (typeValue == "其它特种电源") {
                    var productNameList = eval('${productNameList}'); //所属产品类别
                    common.initDicData("Q_productName_S", productNameList)
                    productNameData=productNameList;
                  }
                  $.ajax({
                    url: "${ctx}/qbdms/wQbdChemicalPhysicsInfo/getSelectData",
                    type: "post",
                    data: {
                      "typeValue": typeValue,
                      "productCategoryValue": 1
                    },
                    dataType: 'json',
                    async: false,
                    success: function (data) {
                      $("#stage").empty();
                      if (typeValue != "弹箭用电源") {
                        common.initDicData("Q_stage_S", data);
                        stageData=data;
                      }
                    },
                    error: function (XMLHttpRequest, textStatus, errorThrown) {
                      layer.alert(publicMethods.confirmStyle(data.msg),{title: false,skin: 'confirm-class'});
                      //执行重载
                      dateReflash();
                    }
                  })
                } else {
                  if (typeValue == "其它特种电源") {
                    return false;
                  }
                  $("#productName").empty();
                  common.initDicData("Q_productName_S", data);
                  productNameData=data;
                }
                form.render();
              },
              error: function (XMLHttpRequest, textStatus, errorThrown) {
                layer.alert(publicMethods.confirmStyle(data.msg),{title: false,skin: 'confirm-class'});
                //执行重载
                reflashQuery(true);
                dateReflash();
              }
            })
          }
        }

        table.on('toolbar(wQbdChemicalPhysicsInfoTable)', function (obj) {
          var checkStatus = table.checkStatus(obj.config.id);
          var data = checkStatus.data;
          var _this = this;
          var layerH=publicMethods.layHeight('.listBody');
          switch (obj.event) {
            case 'add':
              layer.open({
                type: 2,
                area: ['437px', '242px'],
                title: ['选择分类'],
                skin:'qbdms-layerFormBtn',
                content:  '${ctx}/qbdms/wQbdChemicalPhysicsInfo/view/selectType'
              });

              break;

            case 'delete':
              var array = "";
              for (var i = 0; i < data.length; i++) {
                array += data[i].id + ",";
              }
              delFun(data, array);
              break;
            case 'export':
              if (data.length == 0) {
                layer.confirm(publicMethods.confirmStyle('还没有选择，是否导出全部?'),{title: false,skin: 'confirm-class'},
                    function (index) {
                      layer.close(index);
                      var url = serverPath.qbdmsPath + '/qbdms/wQbdChemicalPhysicsInfo/exportData';
                      var param = "";
                      $("form[lay-filter='wQbdChemicalPhysicsInfoQueryForm']").find(".filter-value").each(function (i, value) {
                        param += "&" + this.name + "=" + this.value
                      });
                      open(url, param);
                    });
              } else {
                layer.confirm(publicMethods.confirmStyle('确定导出吗?'),{title: false,skin: 'confirm-class'},
                    function (index) {
                      layer.close(index);
                      var ids = [];
                      for (var i = 0; i < data.length; i++) {
                        ids.push(data[i].id);
                      }
                      var url ='${ctx}/qbdms/wQbdChemicalPhysicsInfo/exportData';
                      open(url, "&id=" + ids);
                    });
              }
              break;
            case "import":
              common.importInit('wQbdChemicalPhysicsInfoTable',"/qbdms/wQbdChemicalPhysicsInfo/importData",true,"/importTemplates/化学物理电源信息.xlsx");
              dateReflash();
              break;
            case "query":
              reflashQuery(false);
              dateReflash();
              break;
            case "clears":
              reflashQuery(true);
              clear();
              break;
            case "screen":
              common.initScreenTop('wQbdChemicalPhysicsInfoTable');
              dateReflash();
              form.render();
              break;
            case "report":
              var array = "";
              for (var i = 0; i < data.length; i++) {
                array+=data[i].id+",";
              }
              //业务表名,勾选数据主键,流程key,table标签lay-filter属性值,form标签lay-filter属性值,是否允许重复上报,页面所在包名,流程定义id
              common.report("W_QBD_CHEMICAL_PHYSICS_INFO",array,"plantToHospital","wQbdChemicalPhysicsInfoTable","wQbdChemicalPhysicsInfoQueryForm",false,"wQbdChemicalPhysicsInfo","plantToHospital:1:72d05d40362249118c5453aa60c6da90");
              dateReflash();
              break;
            case "listStyle":
              layer.open({
                type: 2,
                area: ['80%', layerH],
                skin: 'qbdms-layerFormBtn',
                title: ['新增列表样式', 'font-size:14px;'],
                content: '${ctx}/qbdms/wCustomColumns/view/list',
                success:function (layero, index) {
                  publicMethods.tipsAuto(layero.find('.layui-layer-setwin'),'点击这里关闭弹框哦',2000)
                }
              });
              break;
          }
          ;
        });
        table.on('tool(wQbdChemicalPhysicsInfoTable)', function (obj) {
          var data = obj.data, //获得当前行数据
              layEvent = obj.event; //获得 lay-event 对应的值
          switch (layEvent) {
            case "edit":

              window.location.href = '${ctx}/qbdms/wQbdChemicalPhysicsInfo/view/add?id=' + data.id;
              break;
            case "particulars":

              window.location.href = '${ctx}/qbdms/wQbdChemicalPhysicsInfo/view/particulars?id=' + data.id;
              break;
            case "del":
              delFun(data, data.id);
              break;
          }
        });
        function open(url, param) {
          var curUrl = url;
          layer.open({
            type: 2,
            area: ['700px', '520px'],
            title: ['自定义导出', 'font-size:14px;'],
            content: '${ctx}/qbdms/wQbdChemicalPhysicsInfo/view/export',
            btn: ['确定', '取消'],
            btnAlign: 'c',
            skin: 'qbdms-layerFormBtn',
            yes: function (index, layero) {
              url = curUrl;
              var iframeWin = window["layui-layer-iframe" + index];
              var data = iframeWin.getData();
              if (data) {
                url = url + "?data=" + JSON.stringify(data) + param;
                window.location.href = encodeURI(url)
              }
            }
          });
        }
        function delFun(data, id) {
          if (data.length === 0) {
            layer.msg('请先选择一行数据!',{title: false,skin: 'confirm-class'});
          } else {
            layer.confirm(publicMethods.confirmStyle('确定删除当前数据吗?'),{title: false,skin: 'confirm-class'},function (index) {
              layer.close(index);
              $.ajax({
                url:  "${ctx}/qbdms/wQbdChemicalPhysicsInfo/del",
                type: "post",
                data: {id: id},
                dataType: 'json',
                success: function (data) {
                  layer.alert(publicMethods.confirmStyle(data.msg),{title: false,skin: 'confirm-class'});
                  //执行重载
                  reflashQuery(true);
                  dateReflash();
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                  layer.alert(publicMethods.confirmStyle(data.msg),{title: false,skin: 'confirm-class'});
                  //执行重载
                  reflashQuery(true);
                  dateReflash();
                }
              })
            })
          }
        }
        window.Initialization = function () {
          reflashQuery(false);
          dateReflash();
        };
        /*刷新时间控件*/
        //list页面初始化展开按钮tips展示（展开按钮类名）
        publicMethods.tipsAuto('.screen')
        //筛选条件初始化（页面表格的Id，是否初始化（true、false））
        common.initScreenTop('wQbdChemicalPhysicsInfoTable',true);
        common.tableSort("wQbdChemicalPhysicsInfoTable");
        // dateReflash();
        var typeList = eval('${typeList}'); //种类
        common.initDicData("Q_type_S", typeList)
      });
</script>
</body>
</html>